var ctx=window.daijia.ctx;
var lng=window.daijia.lng;
var lat=window.daijia.lat;

$(document).ready(function(){
	
	var point = new BMap.Point(lng, lat);
	
	if (point) {
		var map = new BMap.Map("allmap3");
		map.centerAndZoom(point, 11);
	    map.enableScrollWheelZoom();
	    
	    if(isSupportCanvas()){

			var heatmapOverlay = new BMapLib.HeatmapOverlay({"radius":30});
			map.addOverlay(heatmapOverlay);
		    /*$.post(ctx+"/errand/errandHeatMapData",function(data) {
		    	heatmapOverlay.setDataSet({data:data,max:100});
		        heatmapOverlay.show();
					
		        
			},"json");*/
			
		}
	}
	else{
		$.scojs_message("地区"+center+"位置不准确，请重新编辑地区", $.scojs_message.TYPE_ERROR);
	}
	
    function isSupportCanvas(){
        var elem = document.createElement('canvas');
        return !!(elem.getContext && elem.getContext('2d'));
    }
    $("#errandMonth").change(function(){
    	var month = $(this).val();
    	 $.post(ctx+"/errand/errandHeatMapData",{month:month,year:$("#year_errand").val()},function(data) {
		    	heatmapOverlay.setDataSet({data:data,max:100});
		        heatmapOverlay.show();
			},"json");
    	
    });
    
    $("#year_errand").change(function(){
    	var year_errand = $(this).val();
    	
    	 $.post(ctx+"/errand/errandHeatMapData",{year:year_errand,month:$("#errandMonth").val()},function(data) {
		    	heatmapOverlay.setDataSet({data:data,max:100});
		        heatmapOverlay.show();
			},"json");
    	
    });
    $("#errandMonth").val(new Date().getMonth()+1);
    $.post(ctx+"/errand/errandHeatMapData",{year:$("#year_errand").val(),month:$("#errandMonth").val()},function(data) {
    	heatmapOverlay.setDataSet({data:data,max:100});
        heatmapOverlay.show();
	},"json");
   
    
 
});
